package com.jzmy.employment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jzmy.employment.dao.ResumesDao;
import com.jzmy.employment.entity.Resumes;
import com.jzmy.employment.service.ResumesService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * @author mengzhichao
 * @create 2022-08-26-17:30
 */
@Service
public class ResumesServiceImpl extends ServiceImpl<ResumesDao,Resumes> implements ResumesService {
    @Override
    public Resumes findOneByKv(Object... params) {
        return getOne(this.convertToEntityWrapper(params));
    }

    private QueryWrapper<Resumes> convertToEntityWrapper(Object... params) {
        QueryWrapper<Resumes> ew = new QueryWrapper<>();
        if (params == null) {
            return ew;
        }
        for (int i = 0; i < params.length; i++) {
            if (i % 2 == 1 && params[i] != null && StringUtils.isNotBlank(params[i].toString())) {
                if(String.valueOf(params[i - 1]).equals("name")){
                    ew.like((String) params[i - 1], params[i].toString());
                }else if(String.valueOf(params[i - 1]).equals("file_name")){
                    ew.like((String) params[i - 1], params[i].toString());
                }else if(String.valueOf(params[i - 1]).equals("title")){
                    ew.like((String) params[i - 1], params[i].toString());
                }else if(String.valueOf(params[i - 1]).equals("introduce")){
                    ew.like((String) params[i - 1], params[i].toString());
                }else{
                    ew.eq((String) params[i - 1], params[i].toString());
                }
            }
        }
        return ew;
    }

}
